﻿using UnityEngine;
using System.Collections;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class UtilsEditor : MonoBehaviour
{

    public static void CreateAsset(Object obj, string fileName, string path)
    {
        if(!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        AssetDatabase.CreateAsset(obj, path + fileName);
        EditorUtility.SetDirty(obj);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }

    /// <summary>
    /// 读取ScriptableObject资源
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="fileName"></param>
    /// <param name="path">path为从Assets/目录开始</param>
    /// <returns></returns>
    public static T loadAsset<T>(string fileName, string path) where T : Object
    {
        string finalPath = path + "/" + fileName;
        T asset = AssetDatabase.LoadAssetAtPath<T>(finalPath);
        return asset;

    }

    public static void CreateDirectory(string path)
    {
        if(!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
    }
}
